function crit1_v4

 

%version 0: 04/04/09 - Calculates hard and soft changeovers for a set

%schedule

%--------------------------------------------------------------------------

%version 1: 04/04/09 - Calculates hard and soft changeovers for a set

%schedule.  The import file should be the IPC schedule (numbers) in the

%first column followed by the binary FSI inclusions (utilizes hard

%changeover avoidence)

%--------------------------------------------------------------------------

%version 2: 04/04/09 - basic greedy heuristic

%--------------------------------------------------------------------------

%version 3: 04/04/09 - the sorting of replacement fsi's in the existing

%collator now takes into account whether the fsi being replaced was used in

%the previous IPC

%--------------------------------------------------------------------------

%version 4: 04/04/09 - added

 

%        for zer = 1:col;

%            if countzeros + COL(zer) == countzeros;

%                countzeros2 = countzeros2 + 1;

%            end

%        end

%        X3 = zeros(g+countzeros2-1,3);    

 

%This accounts for multiple open hoppers on the collator so that more than

%one will be used to avoid hard-changeovers

%--------------------------------------------------------------------------

%--------------------------------------------------------------------------

 

A = xlsread('test_worst_fsi');

tic

 

 

SUMROW = sum(A,2);

[dd ee]=size(SUMROW);

TEMP2 = (1:1:dd)';

IPC = [TEMP2 SUMROW];

 

 

 

SUMCOL = sum(A,1);

FSI_PERCENT = SUMCOL/dd;

 

 

[n m] = size(A);

col = 50;

col2 = 80 - col;

 

START = A * FSI_PERCENT';

TEMP1 = [IPC START];

 

% = [IPC# totalFSI rank(# of FSI) FSIusage]

IPC_INFO = sortrows(TEMP1,-3);

 

FSI_NUM = (1:1:m); %needed?

 

 

 

H = IPC_INFO(:,1);

 

COL = zeros(1,col);

 

 

 

%initial collator population

x=1;

for i = 1:m;

    if A(H(1),i) == 1;

        COL(1,x) = i;

        x=x+1;

    end

end

 

SCHED = [H(1) 0 0 COL];

H(1)=[];

H=sortrows(H,1);

 

 

for l = 1:n-1;

NEXT2=[];

for i = 1:n-l;

        countzeros = 0;

        countzeros2 = 0;       

        NEXT1 = [];

        soft = 0;

        hard = 0;

        COL_TEMP = COL;

        X0 = find(A(H(i),:) == 1);

        X1 = setdiff(X0,COL_TEMP);

        [q w] = size(X1);

        X2 = setdiff(COL_TEMP,X0);

        [f g] = size(X2);

        for zer = 1:col;

            if countzeros + COL(zer) == countzeros;

                countzeros2 = countzeros2 + 1;

            end

        end

        X3 = zeros(g+countzeros2-1,3);

        for k = 1:g;

            if X2(1,k)~=0;

               

                A_TEMP = A(H,:);

                [tt yy] = size(A_TEMP);

                SUMCOL_TEMP = sum(A_TEMP,1);

                FSI_PERCENT_TEMP = SUMCOL_TEMP/tt;

               

                X3(k,1) = X2(1,k);

                X3(k,2) = FSI_PERCENT_TEMP(1,X2(k));

                if X2(1,k) - A(SCHED(l,1),X2(1,k)) ~= X2(1,k);

                    X3(k,3) = 1;

                else

                    X3(k,3) = .5;

                end

            end

        end

        X3 = sortrows(X3,[3 2]);

        X3(:,2)=[];

        X3(:,2)=[];

 

    for j = 1:w;

        X4 = find(COL_TEMP == X3(j));

        if X3(j,1)~=0 && X3(j,1) - A(SCHED(l,1),X3(j,1)) ~= X3(j,1);

            hard = hard + 1;

        else

            soft = soft + 1;

        end

        COL_TEMP(X4(1)) = X1(1);

        X1(1)=[];

    end

 

NEXT1 = [H(i) hard soft COL_TEMP];

NEXT2 = [NEXT2;NEXT1];

end

 

if i < n;

        NEXT2 = sortrows(NEXT2,[2,3]);

        COL = NEXT2(1,4:col+3);

        SCHED = [SCHED; NEXT2(1,:)];

        H=setdiff(H,NEXT2(1,1))';

elseif i == n;

        SCHED = [SCHED; NEXT2(1,:)];

        H=setdiff(H,NEXT2(1,1))';

end

end

toc

xlswrite(['results_' date], SCHED);

hardtotal = sum(SCHED(:,2))

softtotal = sum(SCHED(:,3))